﻿using SqlSugar; 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace Raffles.OA.Data
{
    /// <summary>
    /// 用户类
    /// </summary>
    [SugarTable("Sys_User")]
    public partial class User : BaseEntity
    {
        /// <summary>
        /// 部门Id
        /// </summary>
        public int DepartmentId { get; set; }
        /// <summary>
        /// 账号
        /// </summary>
        [DisplayName("员工账户")]
        public string Account { get; set; } 
        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; } 
        /// <summary>
        /// 盐值
        /// </summary>
        public string Salt { get; set; }
        /// <summary>
        /// 真实姓名
        /// </summary>
        [DisplayName("员工姓名")]
        public string RealName { get; set; }
        /// <summary>
        /// 手机号码
        /// </summary>
        [DisplayName("手机号码")]
        public string MobilePhone { get; set; } 
        /// <summary>
        /// 电子邮件
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// 岗位Id
        /// </summary>
        public string PositionId { get; set; } 
        /// <summary>
        /// 颜色
        /// </summary>
        public string Color { get; set; }
        /// <summary>
        /// 操作率
        /// </summary>
        public decimal OperateRate { get; set; }
        
        /// <summary>
        /// 是否部门主管
        /// </summary>
        public bool IsManager { get; set; } = false;
        /// <summary>
        /// 是否管理员
        /// </summary>
        public bool IsSystem { get; set; } = false;
        /// <summary>
        /// 备注说明
        /// </summary>
        public string Description { get; set; } 
        /// <summary>
        /// 启用状态
        /// </summary>
        public bool EnabledMark { get; set; } = true;
        /// <summary>
        /// 删除状态
        /// </summary>
        public bool DeletedMark { get; set; } = false;
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreatedOn { get; set; } = DateTime.Now;
        /// <summary>
        /// 创建人员
        /// </summary>
        public int? CreatedBy { get; set; }
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? UpdatedOn { get; set; }
        /// <summary>
        /// 更新人员
        /// </summary>
        public int? UpdatedBy { get; set; } 
    }
    public partial class User
    {
        [Navigate(NavigateType.OneToOne, nameof(DepartmentId))]
        public Department Department { get; set; }
        /// <summary>
        /// 多对多
        /// </summary>
        [Navigate(typeof(UserRole), nameof(UserRole.UserId), nameof(UserRole.RoleId))]
        public List<Role> Roles { get; set; }

        [Navigate(typeof(RoleMenu), nameof(RoleMenu.UserId), nameof(RoleMenu.MenuId))]
        public List<Menu> Menus { get; set; }
    }

    public partial class User
    {
        /// <summary>
        /// 所属角色(目前系统只支持单角色)
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string RoleName { get { return Roles?.FirstOrDefault()?.Name; } }
        /// <summary>
        /// 所属角色(目前系统只支持单角色)
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string RoleCode { get { return Roles?.FirstOrDefault()?.Code; } }
        /// <summary>
        /// 所属部门
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string DepartmentName { get { return Department?.Name; } }
    } 
}
